package com.zzyl.common.utils;


import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.core.auth.Auth;
import com.baidubce.qianfan.model.chat.ChatResponse;
import com.zzyl.common.config.QianFangAIConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class QianFangAIModuleUtil {

    @Autowired
    private QianFangAIConfig qianFangAIConfig;

    public String invoke(String prompt) {
        //第一步创建千帆大模型对象
        Qianfan qianfan = new Qianfan(Auth.TYPE_OAUTH, qianFangAIConfig.getAccessKey(), qianFangAIConfig.getSecretKey());
        //配置千帆大模型
        ChatResponse response = qianfan.chatCompletion()
                .model(qianFangAIConfig.getQianfanModel())
                .addMessage("user", prompt)
                .temperature(0.7)
                .maxOutputTokens(2000)
                .responseFormat("json_object")
                .execute();

        //拿到得到的数据
        String result = response.getResult();
        //返回
        return result;

    }
}
